//
//  LevelSelect.m
//  GameProject
//
//  Created by Blair Trusler on 20/02/2012.
//  Copyright (c) 2012 Blair Trusler. All rights reserved.
//

#import "GameHeader.h"

@implementation LevelSelect

#pragma mark - scene
+(id) scene
{
    CCScene *scene = [CCScene node];
    
    LevelSelect *layer = [LevelSelect node];
    
    [scene addChild: layer];
    
    return scene;
}


#pragma mark - initialize
-(id) init
{
    if( (self=[super init] )) {
        CCLOG(@"Loading Level Select Menu...");
        
        [self loadScreenContents];
        [self setUpSaves];

        
        CCLOG(@"Level Select Menu Loaded.");
    }
    return self;
}

- (void) dealloc {
    [page0 release];
    [page1 release];
    [page2 release];
    [page3 release];
    [page4 release];
    [page5 release];
    [super dealloc];
}


-(void)loadScreenContents{
    tempVC=[[UIViewController alloc] init]; //Init temp VC for Game Center button

    CGSize screenSize = [CCDirector sharedDirector].winSize;
    
    CCSprite *backgroundImage = [CCSprite spriteWithFile:@"GameBackground.png"];
    [backgroundImage setPosition:CGPointMake(screenSize.width/2, screenSize.height/2)]; 

    CCMenuItemImage *returnToTitleScreen = [CCMenuItemImage itemFromNormalImage:@"backbutton.png" selectedImage:@"backbutton.png" target:self selector:@selector(returnToTitleScreen:)];
    CCMenu *returnToTitleScreenMenu = [CCMenu menuWithItems:returnToTitleScreen, nil];
    CCMenuItemImage *menuButton = [CCMenuItemImage itemFromNormalImage:@"pausebutton1.png" selectedImage:@"pausebutton1.png" target:self selector:@selector(loadMenu)];
    CCMenu *menuButtonMenu = [CCMenu menuWithItems:menuButton, nil];

    
    //Scroll Page 0 (random level select)
    page0 = [[CCLayer alloc]init];
    CCSprite *randomLevelLabel = [CCSprite spriteWithFile:@"Random.png"];
    CCSprite *randomLevelMap = [CCSprite spriteWithFile:@"blankmap.png"];
    CCMenuItemImage *playRandomGame = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playRandomLevel:)];
    CCMenu *playRandomGameMenu = [CCMenu menuWithItems:playRandomGame, nil];

    
    //Scroll Page 1
    page1 = [[CCLayer alloc] init];
    CCSprite *level1Label = [CCSprite spriteWithFile:@"Level1.png"];
    CCSprite *level1Description = [CCSprite spriteWithFile:@"Level1_Description.png"];
    CCSprite *level1Map = [CCSprite spriteWithFile:@"Level_1.png"];
    CCMenuItemImage *playGameButton1 = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playLevel1:)];
    CCMenu *playGameMenu1 = [CCMenu menuWithItems:playGameButton1, nil];
    CCMenuItemImage *leaderboardsButton = [CCMenuItemImage itemFromNormalImage:@"Leaderboard.png" selectedImage:@"Leaderboard1.png" target:self selector:@selector(showLeaderboards:)];
    CCMenu *leaderboardsMenu = [CCMenu menuWithItems:leaderboardsButton, nil]; 

    
    
    //Scroll Page 2
    page2 = [[CCLayer alloc] init];
    CCSprite *level2Label = [CCSprite spriteWithFile:@"Level2.png"];
    CCSprite *level2Map = [CCSprite spriteWithFile:@"Level_2.png"];
    CCSprite *level2Description = [CCSprite spriteWithFile:@"Level2_Description.png"];
    CCMenuItemImage *playGameButton2 = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playLevel2:)];
    CCMenu *playGameMenu2 = [CCMenu menuWithItems:playGameButton2, nil];
    CCMenuItemImage *leaderboardsButton2 = [CCMenuItemImage itemFromNormalImage:@"Leaderboard.png" selectedImage:@"Leaderboard1.png" target:self selector:@selector(showLeaderboards2:)];
    CCMenu *leaderboardsMenu2 = [CCMenu menuWithItems:leaderboardsButton2, nil]; 

    
    //Scroll Page 3
    page3 = [[CCLayer alloc] init];
    CCSprite *level3Label = [CCSprite spriteWithFile:@"Level3.png"];
    CCSprite *level3Map = [CCSprite spriteWithFile:@"Level_3.png"];
    CCSprite *level3Description = [CCSprite spriteWithFile:@"Level3_Description.png"];
    CCMenuItemImage *playGameButton3 = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playLevel3:)];
    CCMenu *playGameMenu3 = [CCMenu menuWithItems:playGameButton3, nil];
    CCMenuItemImage *leaderboardsButton3 = [CCMenuItemImage itemFromNormalImage:@"Leaderboard.png" selectedImage:@"Leaderboard1.png" target:self selector:@selector(showLeaderboards3:)];
    CCMenu *leaderboardsMenu3 = [CCMenu menuWithItems:leaderboardsButton3, nil]; 

    page4 = [[CCLayer alloc] init];
    CCSprite *level4Label = [CCSprite spriteWithFile:@"Level4.png"];
    CCSprite *level4Map = [CCSprite spriteWithFile:@"Level_4_Updated.png"];
    CCSprite *level4Description = [CCSprite spriteWithFile:@"Level4_Description.png"];
    CCMenuItemImage *playGameButton4 = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playLevel4:)];
    CCMenu *playGameMenu4 = [CCMenu menuWithItems:playGameButton4, nil];
    CCMenuItemImage *leaderboardsButton4 = [CCMenuItemImage itemFromNormalImage:@"Leaderboard.png" selectedImage:@"Leaderboard1.png" target:self selector:@selector(showLeaderboards4:)];
    CCMenu *leaderboardsMenu4 = [CCMenu menuWithItems:leaderboardsButton4, nil]; 

    
    page5 = [[CCLayer alloc] init];
    CCSprite *level5Label = [CCSprite spriteWithFile:@"Level5.png"];
    CCSprite *level5Map = [CCSprite spriteWithFile:@"Level_5.png"];
    CCSprite *level5Description = [CCSprite spriteWithFile:@"Level5_Description.png"];
    CCMenuItemImage *playGameButton5 = [CCMenuItemImage itemFromNormalImage:@"PlayButton1.png" selectedImage:@"PlayButton2.png" target:self selector:@selector(playLevel5:)];
    CCMenu *playGameMenu5 = [CCMenu menuWithItems:playGameButton5, nil];
    CCMenuItemImage *leaderboardsButton5 = [CCMenuItemImage itemFromNormalImage:@"Leaderboard.png" selectedImage:@"Leaderboard1.png" target:self selector:@selector(showLeaderboards5:)];
    CCMenu *leaderboardsMenu5 = [CCMenu menuWithItems:leaderboardsButton5, nil]; 

    
    
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        returnToTitleScreen.scale = 0.6f;
        returnToTitleScreenMenu.position = ccp(50 , 720);
        menuButton.scale = 0.3f;
        menuButtonMenu.position = ccp(975,720);
        
        randomLevelLabel.position = ccp(screenSize.width /2 , 700);
        level1Label.position = ccp( screenSize.width /2 , 700 );
        level2Label.position = ccp( screenSize.width /2 , 700 );
        level3Label.position = ccp( screenSize.width /2 , 700 );
        level4Label.position = ccp( screenSize.width /2 , 700 );
        level5Label.position = ccp( screenSize.width /2 , 700 );
        
        randomLevelMap.scale = 0.25f;
        randomLevelMap.position = ccp(screenSize.width /2 , screenSize.height /2);
        
        level1Map.scale = 0.35f;
        level1Map.opacity = 75.0f;
        level1Map.position = ccp(screenSize.width /2 , screenSize.height /2);
        level1Description.position = ccp(screenSize.width/2, screenSize.height/2);

        level2Map.scale = 0.25f;
        level2Map.opacity = 75.0f;
        level2Map.position = ccp(screenSize.width /2 , screenSize.height /2);
        level2Description.position = ccp(screenSize.width/2, screenSize.height/2);

        playRandomGameMenu.position = ccp(500,150);
        playGameMenu1.position = ccp(500,150);
        playGameMenu2.position = ccp(500,150);
        playGameMenu3.position = ccp(500,150);
        playGameMenu4.position = ccp (500,150);
        playGameMenu5.position = ccp (500,150);
        
        level3Map.scale = 0.25f;
        level3Map.opacity = 75.0f;
        level3Map.position = ccp(screenSize.width/2, screenSize.height/2);
        level3Description.position = ccp(screenSize.width/2, screenSize.height/2);

        level4Map.scale = 0.20f;
        level4Map.opacity = 75.0f;
        
        level4Map.position = ccp(screenSize.width/2, screenSize.height/2);
        level4Description.position = ccp(screenSize.width/2, screenSize.height/2);
        
        level5Map.scale = 0.25f;
        level5Map.opacity = 75.0f;
        level5Map.position = ccp(screenSize.width/2, screenSize.height/2);
        level5Description.position = ccp(screenSize.width/2, screenSize.height/2);
        
        leaderboardsButton.scale = 0.8;
        leaderboardsButton2.scale = 0.8;
        leaderboardsButton3.scale = 0.8;
        leaderboardsButton4.scale = 0.8;
        leaderboardsButton5.scale = 0.8;

        leaderboardsMenu.position = ccp(screenSize.width/2,45);
        leaderboardsMenu2.position = ccp(screenSize.width/2,45);
        leaderboardsMenu3.position = ccp(screenSize.width/2,45);
        leaderboardsMenu4.position = ccp(screenSize.width/2,45);
        leaderboardsMenu5.position = ccp(screenSize.width/2,45);

        
        [page0 addChild:randomLevelMap];
        [page1 addChild:level1Map];
        [page1 addChild:level1Description];
        [page2 addChild:level2Map];
        [page2 addChild:level2Description];
        [page3 addChild:level3Map];
        [page3 addChild:level3Description];
        [page4 addChild:level4Map];
        [page4 addChild:level4Description];
        [page5 addChild:level5Map];
        [page5 addChild:level5Description];
    }
    else{
        backgroundImage.scale = 0.5f;
        
        returnToTitleScreen.scale = 0.4f;
        returnToTitleScreenMenu.position = ccp(26,screenSize.height*0.9);
        
//        menuButtonMenu.scale = 0.75f;
//        menuButtonMenu.position = ccp(screenSize.width*0.8,screenSize.height*0.78);
        menuButtonMenu.scale = 0.20f;
        menuButtonMenu.position = ccp(250,160);

        randomLevelLabel.scale = 0.5f;
        randomLevelLabel.position = ccp(250 , 275);
        
        
        level1Label.scale = 0.5f;
        level1Label.position = ccp(250, 275);
        level2Label.scale = 0.5f;
        level2Label.position = ccp(250, 275);
        level3Label.scale = 0.5f;
        level3Label.position = ccp(250, 275);
        level4Label.scale = 0.5f;
        level4Label.position = ccp (250, 275);
        level5Label.scale = 0.5f;
        level5Label.position = ccp (250, 275);
        
        playRandomGameMenu.scale = 0.5f;
        playGameMenu1.scale = 0.5f;
        playGameMenu2.scale = 0.5f;
        playGameMenu3.scale = 0.5f;
        playGameMenu4.scale = 0.5f;
        playGameMenu5.scale = 0.5f;
        
        playRandomGameMenu.position = ccp(120,50);
        playGameMenu1.position = ccp(120,50);
        playGameMenu2.position = ccp(120,50);
        playGameMenu3.position = ccp(120,50);
        playGameMenu4.position = ccp(120,50);
        playGameMenu5.position = ccp(120,50);

        level5Label.scale = 0.5f;
        level5Label.position = ccp(250,275);
        
        leaderboardsButton.scale = 0.4;
        leaderboardsButton2.scale = 0.4;
        leaderboardsButton3.scale = 0.4;
        leaderboardsButton4.scale = 0.4;
        leaderboardsButton5.scale = 0.4;
        leaderboardsMenu.position = ccp(250,75);
        leaderboardsMenu2.position = ccp(250,75);
        leaderboardsMenu3.position = ccp(250,75);
        leaderboardsMenu4.position = ccp(250,75);
        leaderboardsMenu5.position = ccp(250,75);
        
    }
    
   // [self addChild:backgroundImage];
    [self addChild:menuButtonMenu];
    [self addChild:returnToTitleScreenMenu];
    
    [page0 addChild:randomLevelLabel];
    [page0 addChild:playRandomGameMenu];
    
    [page1 addChild:level1Label];
    [page1 addChild:playGameMenu1];
    [page1 addChild:leaderboardsMenu];

    [page2 addChild:level2Label];
    [page2 addChild:playGameMenu2];
    [page2 addChild:leaderboardsMenu2];


    [page3 addChild:level3Label];
    [page3 addChild:playGameMenu3];
    [page3 addChild:leaderboardsMenu3];

    [page4 addChild:level4Label];
    [page4 addChild:playGameMenu4];
    [page4 addChild:leaderboardsMenu4];

    [page5 addChild:level5Label];
    [page5 addChild:playGameMenu5];
    [page5 addChild:leaderboardsMenu5];

    CCScrollLayer *scroller = [[CCScrollLayer alloc] initWithLayers:[NSMutableArray arrayWithObjects:page0,page1,page2,page3,page4,page5,nil] widthOffset: 230];
    [self addChild:scroller];
}

-(void)playLevel1:(id)sender{
    CCLOG(@"Start Game - Level 1");
    levelPlayed = 1;
    [AudioManager playMenuButtonClick];
    [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel1];

}

-(void)playLevel2:(id)sender{
    CCLOG(@"Start Game - Level 2");
    levelPlayed = 2;
    [AudioManager playMenuButtonClick];
    [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel2];

}

-(void)playLevel3:(id)sender{
    CCLOG(@"Start Game - Level 3");
    levelPlayed = 3;
    [AudioManager playMenuButtonClick];
    [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel3];

}
-(void)playLevel4:(id)sender{
    CCLOG(@"Start Game - Level 4");
    levelPlayed = 4;
    [AudioManager playMenuButtonClick];
    [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel4];
}

-(void)playLevel5:(id)sender{
    CCLOG(@"Start Game - Level 5");
    levelPlayed = 5;
    [AudioManager playMenuButtonClick];
    [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel5];
}


-(void)playRandomLevel:(id)sender{
    [AudioManager playMenuButtonClick];
    int random = arc4random() % 5;
    if (random == 0){
        levelPlayed = 1;
        [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel1];
    }
    else if (random == 1){
        levelPlayed = 2;
        [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel2];
    }
    else if (random == 2){
        levelPlayed = 3;
        [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel3];
    }
    else if (random == 3){
        levelPlayed = 4;
        [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel4];
    }
    else if (random == 4){
        levelPlayed = 5;
        [[SceneManager sharedSceneManager] runSceneWithID:kGameLevel5];

    }
}


-(void)returnToTitleScreen:(id)sender{
    [AudioManager playMenuButtonClick];
    [[CCDirector sharedDirector] popScene]; //'pops' back to previous scene    

//    [AudioManager playMenuButtonClick];
//    [[SceneManager sharedSceneManager] runSceneWithID:kMainMenuScene];    
}

-(void)loadMenu{
    [AudioManager playMenuButtonClick];
    [[CCDirector sharedDirector] pause];
    CCScene *loadStatScene = [StatMenuScene node];
    [[CCDirector sharedDirector] pushScene: loadStatScene]; //'pushes' stat scene ontop of game scene
    
}

-(void)showLeaderboards:(id)sender{
    CCLOG(@"Show Leaderboards");
    [AudioManager playMenuButtonClick];
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController!=NULL){
        leaderboardController.category = kLeaderboard1;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];

    }
}

-(void)showLeaderboards2:(id)sender{
    CCLOG(@"Show Leaderboards");
    [AudioManager playMenuButtonClick];
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController!=NULL){
        leaderboardController.category = kLeaderboard2;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];
    }
}
-(void)showLeaderboards3:(id)sender{
    CCLOG(@"Show Leaderboards");
    [AudioManager playMenuButtonClick];
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController!=NULL){
        leaderboardController.category = kLeaderboard3;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];
    }
}
-(void)showLeaderboards4:(id)sender{
    CCLOG(@"Show Leaderboards");
    [AudioManager playMenuButtonClick];
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController!=NULL){
        leaderboardController.category = kLeaderboard4;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];
    }
}
-(void)showLeaderboards5:(id)sender{
    CCLOG(@"Show Leaderboards");
    [AudioManager playMenuButtonClick];
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController!=NULL){
        leaderboardController.category = kLeaderboard5;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];
    }
}


-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{
    [AudioManager playMenuButtonClick];
    [tempVC dismissModalViewControllerAnimated:YES];
    [tempVC.view removeFromSuperview];
//    [tempVC release];
}



-(void)setUpSaves{
    
    CGSize screenSize = [CCDirector sharedDirector].winSize;

    //Set up score saving:
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    // Register default high scores - this could be more easily done by loading a .plist instead of manually creating this nested object
    NSDictionary *defaultDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:0],nil]forKey:@"scores"];
    [defaults registerDefaults:defaultDefaults];
    NSDictionary *defaultDefaults1 = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:0],nil]forKey:@"scores2"];
    [defaults registerDefaults:defaultDefaults1];
    NSDictionary *defaultDefaults2 = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:0],nil]forKey:@"scores3"];
    [defaults registerDefaults:defaultDefaults2];
    NSDictionary *defaultDefaults3 = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:0],nil]forKey:@"scores4"];
    [defaults registerDefaults:defaultDefaults3];
    NSDictionary *defaultDefaults4 = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:0],nil]forKey:@"scores5"];
    [defaults registerDefaults:defaultDefaults4];
    [defaults synchronize];
    
    ///////////////////////////////
    
    NSArray *highScores = [defaults arrayForKey:@"scores"];
    NSArray *highScores2 = [defaults arrayForKey:@"scores2"];
    NSArray *highScores3 = [defaults arrayForKey:@"scores3"];
    NSArray *highScores4 = [defaults arrayForKey:@"scores4"];
    NSArray *highScores5 = [defaults arrayForKey:@"scores5"];

    
    //Sprite containing star image (to represent high scores):
    CCSprite *star1 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star2 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star3 = [CCSprite spriteWithFile:@"star.png"];
    //Level 2
    CCSprite *star4 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star5 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star6 = [CCSprite spriteWithFile:@"star.png"];
    //Level 3
    CCSprite *star7 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star8 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star9 = [CCSprite spriteWithFile:@"star.png"];
    //Level 4
    CCSprite *star10 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star11 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star12 = [CCSprite spriteWithFile:@"star.png"];

    //Level 5
    CCSprite *star13 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star14 = [CCSprite spriteWithFile:@"star.png"];
    CCSprite *star15 = [CCSprite spriteWithFile:@"star.png"];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        star1.scale = 0.1f;
        star2.scale = 0.1f;
        star3.scale = 0.1f;
        star1.opacity = 200.0f;
        star2.opacity = 200.0f;
        star3.opacity = 200.0f;
        //Display Stars for Level 1:
        if ([[highScores objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars.
        }
        else if ([[highScores objectAtIndex:0] intValue] == 1){ //1 Star
            star1.position = ccp(500,620);
            [page1 addChild:star1];
        }
        else if ([[highScores objectAtIndex:0] intValue] == 2){ //2 Stars
            star1.position = ccp(475,620);
            star2.position = ccp(525,620);
            [page1 addChild:star1];
            [page1 addChild:star2];
        }
        else if ([[highScores objectAtIndex:0] intValue] == 3){ //3 Stars
            star1.position = ccp(450,620);
            star2.position = ccp(500,620);
            star3.position = ccp(550,620);
            [page1 addChild:star1];
            [page1 addChild:star2];
            [page1 addChild:star3];
        }
        
        //Sprite containing star image (to represent high scores):
        star4.scale = 0.1f;
        star5.scale = 0.1f;
        star6.scale = 0.1f;
        star4.opacity = 200.0f;
        star5.opacity = 200.0f;
        star6.opacity = 200.0f;
        //Display Stars for Level 2:
        if ([[highScores2 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores2 objectAtIndex:0] intValue] == 1){      //1 Star
            star4.position = ccp(500,620);
            [page2 addChild:star4];
            
        }
        if ([[highScores2 objectAtIndex:0] intValue] == 2){      //2 Stars
            star4.position = ccp(475,620);
            star5.position = ccp(525,620);
            [page2 addChild:star4];
            [page2 addChild:star5];
        }    
        if ([[highScores2 objectAtIndex:0] intValue] == 3){      //3 Stars
            star4.position = ccp(450,620);
            star5.position = ccp(500,620);
            star6.position = ccp(550,620);
            [page2 addChild:star4];
            [page2 addChild:star5];
            [page2 addChild:star6];
        }
        
        
        //Sprite containing star image (to represent high scores):
        star7.scale = 0.1f;
        star8.scale = 0.1f;
        star9.scale = 0.1f;
        star7.opacity = 200.0f;
        star8.opacity = 200.0f;
        star9.opacity = 200.0f;
        //Display Stars for Level 3:
        if ([[highScores3 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores3 objectAtIndex:0] intValue] == 1){      //1 Star
            star7.position = ccp(500,620);
            [page3 addChild:star7];
            
        }
        if ([[highScores3 objectAtIndex:0] intValue] == 2){      //2 Stars
            star7.position = ccp(475,620);
            star8.position = ccp(525,620);
            [page3 addChild:star7];
            [page3 addChild:star8];
        }    
        if ([[highScores3 objectAtIndex:0] intValue] == 3){      //3 Stars
            star7.position = ccp(450,620);
            star8.position = ccp(500,620);
            star9.position = ccp(550,620);
            [page3 addChild:star7];
            [page3 addChild:star8];
            [page3 addChild:star9];
        }
        
        
        //Sprite containing star image (to represent high scores):
        star10.scale = 0.1f;
        star11.scale = 0.1f;
        star12.scale = 0.1f;
        star10.opacity = 200.0f;
        star11.opacity = 200.0f;
        star12.opacity = 200.0f;
        //Display Stars for Level 4:
        if ([[highScores4 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores4 objectAtIndex:0] intValue] == 1){      //1 Star
            star10.position = ccp(500,620);
            [page4 addChild:star10];
            
        }
        if ([[highScores4 objectAtIndex:0] intValue] == 2){      //2 Stars
            star10.position = ccp(475,620);
            star11.position = ccp(525,620);
            [page4 addChild:star10];
            [page4 addChild:star11];
        }    
        if ([[highScores4 objectAtIndex:0] intValue] == 3){      //3 Stars
            star10.position = ccp(450,620);
            star11.position = ccp(500,620);
            star12.position = ccp(550,620);
            [page4 addChild:star10];
            [page4 addChild:star11];
            [page4 addChild:star12];
        }
        
        //Sprite containing star image (to represent high scores):
        star13.scale = 0.1f;
        star14.scale = 0.1f;
        star15.scale = 0.1f;
        star13.opacity = 200.0f;
        star14.opacity = 200.0f;
        star15.opacity = 200.0f;
        //Display Stars for Level 5:
        if ([[highScores5 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores5 objectAtIndex:0] intValue] == 1){      //1 Star
            star13.position = ccp(500,620);
            [page5 addChild:star13];
            
        }
        if ([[highScores5 objectAtIndex:0] intValue] == 2){      //2 Stars
            star13.position = ccp(475,620);
            star14.position = ccp(525,620);
            [page5 addChild:star13];
            [page5 addChild:star14];
        }    
        if ([[highScores5 objectAtIndex:0] intValue] == 3){      //3 Stars
            star13.position = ccp(450,620);
            star14.position = ccp(500,620);
            star15.position = ccp(550,620);
            [page5 addChild:star13];
            [page5 addChild:star14];
            [page5 addChild:star15];
        }
        
        
        
        
        //ADD LEVEL 5 HERE
        
        
    }
    else{
        star1.scale = 0.05f;
        star2.scale = 0.05f;
        star3.scale = 0.05f;
        star1.opacity = 200.0f;
        star2.opacity = 200.0f;
        star3.opacity = 200.0f;
        if ([[highScores objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars.
        }
        else if ([[highScores objectAtIndex:0] intValue] == 1){ //1 Star
            star1.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            [page1 addChild:star1];
        }
        else if ([[highScores objectAtIndex:0] intValue] == 2){ //2 Stars
            star1.position = ccp(screenSize.width*0.48,screenSize.height*0.7);
            star2.position = ccp(screenSize.width*0.52,screenSize.height*0.7);
            [page1 addChild:star1];
            [page1 addChild:star2];
        }
        else if ([[highScores objectAtIndex:0] intValue] == 3){ //3 Stars
            star1.position = ccp(screenSize.width*0.45,screenSize.height*0.7);
            star2.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            star3.position = ccp(screenSize.width*0.55,screenSize.height*0.7);
            [page1 addChild:star1];
            [page1 addChild:star2];
            [page1 addChild:star3];
        }
        star4.scale = 0.05f;
        star5.scale = 0.05f;
        star6.scale = 0.05f;
        star4.opacity = 200.0f;
        star5.opacity = 200.0f;
        star6.opacity = 200.0f;
        if ([[highScores2 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores2 objectAtIndex:0] intValue] == 1){      //1 Star
            star4.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            [page2 addChild:star4];
            
        }
        if ([[highScores2 objectAtIndex:0] intValue] == 2){      //2 Stars
            star4.position = ccp(screenSize.width*0.48,screenSize.height*0.7);
            star5.position = ccp(screenSize.width*0.52,screenSize.height*0.7);
            [page2 addChild:star4];
            [page2 addChild:star5];
        }    
        if ([[highScores2 objectAtIndex:0] intValue] == 3){      //3 Stars
            star4.position = ccp(screenSize.width*0.45,screenSize.height*0.7);
            star5.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            star6.position = ccp(screenSize.width*0.55,screenSize.height*0.7);
            [page2 addChild:star4];
            [page2 addChild:star5];
            [page2 addChild:star6];
        }
        
        star7.scale = 0.05f;
        star8.scale = 0.05f;
        star9.scale = 0.05f;
        star7.opacity = 200.0f;
        star8.opacity = 200.0f;
        star9.opacity = 200.0f;
        if ([[highScores3 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores3 objectAtIndex:0] intValue] == 1){      //1 Star
            star7.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            [page3 addChild:star7];
            
        }
        if ([[highScores3 objectAtIndex:0] intValue] == 2){      //2 Stars
            star7.position = ccp(screenSize.width*0.48,screenSize.height*0.7);
            star8.position = ccp(screenSize.width*0.52,screenSize.height*0.7);
            [page3 addChild:star7];
            [page3 addChild:star8];
        }    
        if ([[highScores3 objectAtIndex:0] intValue] == 3){      //3 Stars
            star7.position = ccp(screenSize.width*0.45,screenSize.height*0.7);
            star8.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            star9.position = ccp(screenSize.width*0.55,screenSize.height*0.7);
            [page3 addChild:star7];
            [page3 addChild:star8];
            [page3 addChild:star9];
        }
        
        star10.scale = 0.05f;
        star11.scale = 0.05f;
        star12.scale = 0.05f;
        star10.opacity = 200.0f;
        star11.opacity = 200.0f;
        star12.opacity = 200.0f;
        if ([[highScores4 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores4 objectAtIndex:0] intValue] == 1){      //1 Star
            star10.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            [page4 addChild:star10];
            
        }
        if ([[highScores4 objectAtIndex:0] intValue] == 2){      //2 Stars
            star10.position = ccp(screenSize.width*0.48,screenSize.height*0.7);
            star11.position = ccp(screenSize.width*0.52,screenSize.height*0.7);
            [page4 addChild:star10];
            [page4 addChild:star11];
        }    
        if ([[highScores4 objectAtIndex:0] intValue] == 3){      //3 Stars
            star10.position = ccp(screenSize.width*0.45,screenSize.height*0.7);
            star11.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            star12.position = ccp(screenSize.width*0.55,screenSize.height*0.7);
            [page4 addChild:star10];
            [page4 addChild:star11];
            [page4 addChild:star12];
        }
        
        star13.scale = 0.05f;
        star14.scale = 0.05f;
        star15.scale = 0.05f;
        star13.opacity = 200.0f;
        star14.opacity = 200.0f;
        star15.opacity = 200.0f;
        if ([[highScores5 objectAtIndex:0] intValue] == 0){      //0 Stars
            //Display no stars
        }
        if ([[highScores5 objectAtIndex:0] intValue] == 1){      //1 Star
            star13.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            [page5 addChild:star13];
            
        }
        if ([[highScores5 objectAtIndex:0] intValue] == 2){      //2 Stars
            star13.position = ccp(screenSize.width*0.48,screenSize.height*0.7);
            star14.position = ccp(screenSize.width*0.52,screenSize.height*0.7);
            [page5 addChild:star13];
            [page5 addChild:star14];
        }    
        if ([[highScores5 objectAtIndex:0] intValue] == 3){      //3 Stars
            star13.position = ccp(screenSize.width*0.45,screenSize.height*0.7);
            star14.position = ccp(screenSize.width*0.5,screenSize.height*0.7);
            star15.position = ccp(screenSize.width*0.55,screenSize.height*0.7);
            [page5 addChild:star13];
            [page5 addChild:star14];
            [page5 addChild:star15];
        }
        
        
        
    }
}




@end

